import React, { useEffect } from "react";
import { isAndroid } from "react-device-detect";
import "./App.css";

const App = () => {
  useEffect(()=>{
    if(!isAndroid){
      const timestamp = Date.now();
      console.log('Current Timestamp:', timestamp);
      const basicParams = JSON.stringify({
        timestamp: timestamp,
        channel: '1',
        appsFlyerUID: '',
        appCode: 'sparksy_ios',
        applicationID: 'com.meboo.ios',
        appVersion: '1',
        token: '',
        appVersionName: '1.2.0',
        appSource: '2',
        from: '1'
    });
      try {
        fetch("https://sc2-api.imeboo.com/api/app/device/ip", {
          method: "POST",
          headers: {
            "Content-Type": "application/json",
            "basicParams":basicParams
          },
          body: JSON.stringify({
            type: 1,
          }),
        });
      } catch (error) {
        console.error('Error:', error);
      }
    }
  },[])

  const navigateToURL = () => {
    // window.location.href = "https://hourse.onelink.me/g1Pu/dx6ic4k8";
    window.open("https://hourse.onelink.me/g1Pu/dx6ic4k8", "_blank");
  };
  const navigateToURL1 = async () => {
    const textToCopy = "Welcome To Meboo!";
    try {
      await navigator.clipboard.writeText(textToCopy);
    } catch (err) {
      console.error("无法写入剪切板: ", err);
    }

    window.location.href = "https://mbweb.onelink.me/pv0e/lj4bf362";
  };
  return (
    <div>
      {isAndroid ? (
        <div className="container" onClick={navigateToURL}>
          <div className="main">
            <img className="downbg" src="./downbg.jpg" />
            <img className="finger" src="./finger.gif" />
          </div>
        </div>
      ):
    (
        <div className="container" onClick={navigateToURL1}>
          <div className="main">
            <img className="downbg" src="./downbgios.jpg" />
            <img className="fingerios" src="./finger.gif" />
          </div>
        </div>
      )}
    </div>
  );
};

export default App;
